# --*-- coding: utf-8 -*-
import numpy as np
import cv2
import sys

if __name__ == "__main__":
    if len(sys.argv) > 1:
        image = cv2.imread(sys.argv[1], cv2.IMREAD_GRAYSCALE)
    else:
        print("Usage: xxx imagefile")
        exit
    
    h, w = image.shape
    print("h = ", h, ", w = ", w)
    src = np.array([[0,0], [w - 1, 0], [0, h - 1], [w-1, h-1]], np.float32)
    dst = np.array([[50,50], [w/3, 50], [50, h-1], [w-1, h-1]], np.float32)
    p = cv2.getPerspectiveTransform(src, dst)
    r = cv2.warpPerspective(image, p, (w, h), borderValue = 125)
    cv2.imshow("image", image)
    cv2.imshow("warpPerspective", r)
    cv2.waitKey(0)
    cv2.destoryAllWindows()